package com.lmind.support.mail;

import java.util.concurrent.Executor;

import javax.mail.internet.MimeMessage;

import com.lmind.core.mail.IMailService;

public class ThreadPoolMailService implements IMailService {
	
	private IMailService mailService;
	
	private Executor executor;

	public IMailService getMailService() {
		return mailService;
	}

	public void setMailService(IMailService mailService) {
		this.mailService = mailService;
	}
	
	public Executor getExecutor() {
		return executor;
	}

	public void setExecutor(Executor executor) {
		this.executor = executor;
	}

	@Override
	public MimeMessage createMimeMessage() {
		return mailService.createMimeMessage();
	}

	@Override
	public void sendMimeMessage(MimeMessage message) {
		
		final MimeMessage msg = message;
		
		executor.execute(new Runnable() {
			@Override
			public void run() {
				mailService.sendMimeMessage(msg);
			}
		});
	}

}
